package sctu.edu.java.year2016.team05.project;

        import sctu.edu.java.year2016.team01.xuhanmei.day20160529.KnowAbstract1.Apple;

        import javax.swing.*;
        import java.applet.AudioClip;
        import java.awt.*;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
        import java.awt.event.MouseAdapter;
        import java.awt.event.MouseEvent;
        import java.io.File;
        import java.io.IOException;
        import java.net.MalformedURLException;
        import java.net.URI;
        import java.net.URISyntaxException;
        import java.net.URL;

/**
 */
public class User extends JFrame{
    String musicName;
    AudioClip music;
    URL url;
    static String str0;
    String a0="123456",a1="000000";
    String b0="123456",b1="000000";
    JLabel jbll;
    JTabbedPane jtp;
    JPanel jb2,jb3;
    JLabel jb2_1,jb2_2,jb2_3,jb3_1,jb3_2,jb3_3;
    JTextField jb2_jbf,jb3_jbf;
    JPasswordField jb2_jbf1,jb3_jbf1;
    JCheckBox jb2_jcb1,jb3_jcb1;
    JPanel jpl;
    JButton jbl_1,jbl_2,jbt2_1;
    private ImageIcon titleIcon;
    public User(){


        musicName="src\\main\\java\\sctu\\edu\\java\\year2016\\team05\\project\\Music\\nextturn.wav";
        try {
            url=new URL("file:"+new File(".").getCanonicalPath()+"//"+musicName);
            music= JApplet.newAudioClip(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        titleIcon=new ImageIcon("src\\main\\java\\sctu\\edu\\java\\year2016\\team05\\project\\Textures\\1.jpg");
        Image tilteIcon=titleIcon.getImage();
        setIconImage(tilteIcon);


        jbll=new JLabel(new String("IT运维平台"));
        //上方
        jb2=new JPanel(new GridLayout(3,3));
        jb2_1=new JLabel("用户名",JLabel.CENTER);
        jb2_2=new JLabel("密码",JLabel.CENTER);
        jb2_3=new JLabel("    ");
        jb2_jbf=new JTextField();
        jb2_jbf1=new JPasswordField();
        jbt2_1=new JButton("clear");
        jbt2_1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                music.play();
                jb2_jbf.setText("");
                jb2_jbf1.setText("");
            }
        });
        jb2_jcb1=new JCheckBox("记住密码");
        //将控件加入
        jb2.add(jb2_1);
        jb2.add(jb2_jbf);
        jb2.add(jbt2_1);
        jb2.add(jb2_2);
        jb2.add(jb2_jbf1);
        jb2.add(jb2_3);
        jb2.add(jb2_jcb1);
        //创建选项卡窗口
        jtp=new JTabbedPane();
        jtp.add("用户",jb2);
        jb3=new JPanel();
        //用户
        jb3=new JPanel(new GridLayout(3,3));
        jb3_1=new JLabel("管理员",JLabel.CENTER);
        jb3_2=new JLabel("密码",JLabel.CENTER);
        jb3_3=new JLabel("    ");
        jb3_jbf=new JTextField();
        jb3_jbf1=new JPasswordField();
        jbt2_1=new JButton("clear");
        jbt2_1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                music.play();
                jb3_jbf.setText("");
                jb3_jbf1.setText("");
            }
        });
        jb3_jcb1=new JCheckBox("记住密码");
        jb3.add(jb3_1);
        jb3.add(jb3_jbf);
        jb3.add(jbt2_1);
        jb3.add(jb3_2);
        jb3.add(jb3_jbf1);
        jb3.add(jb3_3);
        jb3.add(jb3_jcb1);
        jb3.setVisible(true);
        jtp.add("管理员", jb3);
        //管理员


        //中部
        jpl=new JPanel();
        jbl_1=new JButton(new String("登录"));//登录按钮

        jbl_1.addActionListener(new ActionListener() {

                                    public void actionPerformed(ActionEvent e) {
                                        music.play();
                                        //添加用户及密码
                                        if(jb2_jbf.getText().trim().equalsIgnoreCase(a0) && jb2_jbf1.getText().trim().equalsIgnoreCase(b0)) {
                                            new Menu_plus(User.this).setVisible(true);
                                        }else if(jb3_jbf.getText().trim().equalsIgnoreCase(a1) && jb3_jbf1.getText().trim().equalsIgnoreCase(b1)){
                                            new Manage(User.this).setVisible(true);
                                        }
                                    }
                                }
        );
        jbl_2=new JButton(new String("取消"));
        jbl_2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                music.play();
                jb2_jbf.setText("");
                jb2_jbf1.setText("");
            }
        });
        jpl.add(jbl_1);
        jpl.add(jbl_2);

        this.add(jtp,"Center");
        this.add(jpl, "South");
        this.add(jbll, "North");
        this.setSize(500, 230);//窗口大小
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    //下方

    public static void main(String[] args) {
        User user =new User();
    }
}


class Mesure1 extends JDialog {

    public Mesure1(Menu_plus frame) {

        super(frame, "解决方案", true);
        JLabel l1 = new JLabel();  l1.setText("Mesure1");
        Container container = getContentPane();
        // Label l1 = new Label("go die");
        container.add(l1);

        setBounds(150, 100, 300, 250);

    }
}

class Mesure2 extends JDialog {

    public Mesure2(Menu_plus frame) {

        super(frame, "解决方案", true);

        Container container = getContentPane();
        Label l1 = new Label();
        l1.setText("Mesure2");
        container.add(l1);

        setBounds(150, 100, 300, 250);
    }
}



class Mesure3 extends JDialog {

    public Mesure3(Menu_plus frame) {

        super(frame, "解决方案", true);

        Container container = getContentPane();
        Label l1 = new Label("Mesure3 ");
        container.add(l1);

        setBounds(150, 100, 300, 250);
    }

}
class Mesure4 extends JDialog {
    String musicName;
    AudioClip music;
    URL url;
    public static String a;
    public Mesure4(Menu_plus frame) {

        super(frame, "解决方案", true);

        Container container = getContentPane();

        musicName="src\\main\\java\\sctu\\edu\\java\\year2016\\team05\\project\\Music\\nextturn.wav";
        try {
            url=new URL("file:"+new File(".").getCanonicalPath()+"//"+musicName);
            music= JApplet.newAudioClip(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Label l1 = new Label("Question:" );
        JTextField userText = new JTextField(10);
        userText.setBounds(100, 75, 165, 25);
        JTextField userText2 = new JTextField(10);

        userText2.setText(Manage.b);
        userText2.setBounds(100, 120, 165, 25);

        container.add(userText);
        container.add(userText2);

        container.add(l1);

        setBounds(150, 100, 300, 250);
        JButton referButton = new JButton("refer");
        referButton.setBounds(10, 10, 80, 25);
        container.add(referButton, "South");
        referButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                music.play();
                a = userText.getText();

                JButton jb = (JButton) e.getSource();
                if (jb == referButton) {
                    Manage.getWindows();
                }
            }
        });
        referButton.addActionListener(new ActionListener() {

                                          public void actionPerformed(ActionEvent e) {

                                              new Reminder(Mesure4.this).setVisible(true);
                                          }

                                      }

        );
    }


}
class Manage extends JDialog {
    public static String b;
    String musicName;
    AudioClip music;
    URL url;
    public Manage(User frame) {

        super(frame, "用户反馈", true);
        Container container = getContentPane();
        musicName="src\\main\\java\\sctu\\edu\\java\\year2016\\team05\\project\\Music\\nextturn.wav";
        try {
            url=new URL("file:"+new File(".").getCanonicalPath()+"//"+musicName);
            music= JApplet.newAudioClip(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Label l1 = new Label("Meassage:" );
        JLabel aa=new JLabel("用户遇到的问题是：");
        JTextField userText11 = new JTextField(10);
        userText11.setBounds(100, 70, 165, 25);
        userText11.setText(Mesure4.a);

        JTextField userText12 = new JTextField(10);
        userText12.setBounds(100, 120, 165, 25);


        JButton replay=new JButton("回复");
        container.add(aa,"North");
        container.add(replay, "South");
        container.add(userText11);
        container.add(userText12);
        container.add(l1);
        replay.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                music.play();
                b =userText12.getText();

                JButton jb = (JButton) e.getSource();
                if (jb == replay) {
                    Manage.getWindows();
                }
            }
        });


        setBounds(150, 100, 300, 250);

    }


}
class Reminder extends JDialog {

    public Reminder(Mesure4 frame) {

        super(frame, "reminder ", true);

        Container container = getContentPane();
        Label l1 = new Label("               success ");
        l1.setLocation(75, 50);
        container.add(l1);


        setBounds(150, 100, 200, 200);
    }

}



class Menu_plus extends JDialog {

    private ImageIcon titleIcon;
    String musicName;
    AudioClip music;
    URL url;


    public Menu_plus(User frame) {


        super(frame, "Computer First-Aid", true);

        setSize(400, 300);//这里加一句设置JFrame大小

        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);//这里加一句设置JFrame关闭


        Container container = getContentPane();

        container.setLayout(null);



        titleIcon=new ImageIcon("src\\main\\java\\sctu\\edu\\java\\year2016\\team05\\project\\Textures\\1.jpg");
        Image tilteIcon=titleIcon.getImage();
        setIconImage(tilteIcon);

        musicName="src\\main\\java\\sctu\\edu\\java\\year2016\\team05\\project\\Music\\nextturn.wav";
        try {
            url=new URL("file:"+new File(".").getCanonicalPath()+"//"+musicName);
            music= JApplet.newAudioClip(url);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


        JButton bl = new JButton("蓝屏");

        bl.setBounds(10, 20, 100, 50);


        bl.addActionListener(new ActionListener() {


                                 public void actionPerformed(ActionEvent e) {
                                     music.play();
                                     new Mesure1(Menu_plus.this).setVisible(true);
                                 }

                             }

        );


        container.add(bl);


        JButton b2 = new JButton("死机");

        b2.setBounds(10, 100, 100, 50);


        b2.addActionListener(new ActionListener() {

                                 public void actionPerformed(ActionEvent e) {
                                     music.play();
                                     new Mesure2(Menu_plus.this).setVisible(true);
                                 }

                             }

        );


        container.add(b2);

        JButton b3 = new JButton("无声音");

        b3.setBounds(250, 20, 100, 50);


        b3.addActionListener(new ActionListener() {

                                 public void actionPerformed(ActionEvent e) {
                                     music.play();
                                     new Mesure3(Menu_plus.this).setVisible(true);
                                 }

                             }

        );

        container.add(b3);
        JButton b4 = new JButton("其他");

        b4.setBounds(250, 100, 100, 50);


        b4.addActionListener(new ActionListener() {

                                 public void actionPerformed(ActionEvent e) {
                                     music.play();
                                     new Mesure4(Menu_plus.this).setVisible(true);
                                 }

                             }

        );


        container.add(b4);


        JButton Idea = new JButton("其它问题：https://www.baidu.com/");
        this.add(Idea);
        Idea.setBounds(20, 200, 250, 20);
        container.add(Idea);
        Idea.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                URI uri;
                music.play();

                try {
                    uri=new URI("https://www.baidu.com/");
                    Desktop dtp = Desktop.getDesktop();
                    //是否支持此类和对象浏览
                    if(Desktop.isDesktopSupported()&&dtp.isSupported(Desktop.Action.BROWSE)){
                        dtp.browse(uri);
                    }
                } catch (URISyntaxException e1) {
                    e1.printStackTrace();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }


            }
            public void mouseEntered(MouseEvent e) {

                Idea.setBackground(Color.blue);
            }

            public void mouseExited(MouseEvent e) {
                Idea.setForeground(Color.red);

            }

        });


    }
}

